package com.water.devtool;

import java.util.HashMap;
import java.util.List;

import com.watermud.util.StringUtil;
import com.watermud.util.db.DBUtil;

public class TableUtilForPostgreSQL extends BaseTableUtil implements ITableUtil {

	public static String columnSql = "SELECT col_description(t.oid,c.ordinal_position) COLUMN_COMMENT,c.* FROM information_schema.\"columns\" c,pg_class t WHERE c.\"table_name\"=?  and t.relname = c.\"table_name\" ";
	public static String allTableSql = "SELECT tablename FROM pg_tables where schemaname = ? ";
	public static String tabComSql = "select t.TABLE_COMMENT from information_schema.tables t where  table_name = ?";

	public List getAllTable() {
		String tableSchema = ConfUtil.getValue("tableSchema");
		if (StringUtil.isNull(tableSchema)) {
			tableSchema = "public";
		}

		return DBUtil.queryForList(allTableSql, new Object[] { tableSchema.toLowerCase() }, HashMap.class);
	}

	public List getAllColumn(String table) {
		return DBUtil.queryForList(columnSql, new Object[] { table }, HashMap.class);
	}

	@Override
	public String getTableComment(String table) {
		return DBUtil.queryForString(tabComSql, new Object[] { table });
	}

}
